************************************************************************** 
* Replication of Table 1 of Cycle Continues (2025)- Initial Elections
**************************************************************************
clear
local current_path = c(pwd)
set scheme plotplain, permanently
cd "`current_path'"

* 
use "ddrla.dta", replace

preserve
keep if initialelecyr == 1  // Step 1: Keep only initial elections
keep year ctry initialelecyr // Step 2: Keep only variables for table
sort ctry year                     // Step 3: Sort by country and year
by ctry: gen election_seq = _n     // Step 4: Create sequence number
reshape wide year, i(ctry) j(election_seq) // Step 5: Reshape to wide format
rename year* initial_election*        // Step 6: Rename columns
export excel "Initial_Elections_Table.xlsx", firstrow(variables) replace // Export to Excel
restore
